<?php
/**
 * SDK错误码 
 */
#@todo
class SDOServiceErrorCode
{
    /*
     * 错误号
     */
    const API_EC_SUCCESS            = 0;
    const API_EC_UNKNOWN            = -20001001;
    const API_EC_SERVICE            = -20001400;
    const API_EC_TIMEOUT            = -20001501;
    const API_EC_METHOD             = -20001600;
    const API_EC_PARAM              = -20001700;     
    const API_EC_TOO_MANY_CALLS     = -20001701;  
    const API_EC_COMMON_ERROR       = -20001800;
    const API_EC_MATCH              = -20001900;
    
    
    /*
     * 错误号与错误字符串映射
     */
    static protected $errorCode = array(
        self::API_EC_SUCCESS        => 'success',
        self::API_EC_UNKNOWN        => 'An unknown error occurred.',
        self::API_EC_SERVICE        => 'Service temporarily unavailable.',
        self::API_EC_TIMEOUT        => 'TIMEOUT.',
        self::API_EC_METHOD         => 'Invalid Method Name',
        self::API_EC_PARAM          => 'Invalid Parameter.',
        self::API_EC_TOO_MANY_CALLS => 'Application request limit reached.',
        self::API_EC_COMMON_ERROR   => 'Interface error',
        self::API_EC_MATCH          => 'A AND B not matched',
   );
   
   /*
     * 通过错误号构造错误返回
     * @param int $code 错误号
     * @param string $msg 错误信息
     * @return array
     */
    static function populateError($code, $msg)
    {
        return array("errNo"=>$code, "errMsg"=>$msg);
    } 
    
    static function getMessage($code=null)
    {
        if (!$code) {
        	return self::$errorCode;
        }  
        return self::$errorCode[$code];     
    }
}